<?
/**
 * Copyright 2008 Melange.
 *
 * This file is part of Melange CMS
 *
 * @package cms
 *
 */


/**
 * Requirements
 */
require_once("mvc/action/ActionForm.php");
require_once("mvc/action/ActionMessage.php");
require_once("mvc/action/ActionMessages.php");
require_once("cms/download/om/DownloadRevision.php");



/**
 * BaseDownloadForm Class
 *
 * @category    Melange CMS
 * @package     cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 */
class BaseDownloadForm extends ActionForm {


    // ----------------------------------------------------- Instance Variables


    /**
     * revision
     *
     * @var DownloadRevision 
     */
    protected $revision;


    /**
     * publicationDay
     *
     * @var mixed 
     */
    protected $publicationDay;


    /**
     * publicationMonth
     *
     * @var mixed 
     */
    protected $publicationMonth;


    /**
     * publicationYear
     *
     * @var mixed 
     */
    protected $publicationYear;


    /**
     * formFile
     *
     * @var mixed 
     */
    protected $formFile;


    /**
     * formImage
     *
     * @var mixed 
     */
    protected $formImage;


    /**
     * deleteImage
     *
     * @var mixed 
     */
    protected $deleteImage;


    /**
     * overwrite
     *
     * @var mixed 
     */
    protected $overwrite;


    // ----------------------------------------------------------- Constructors


    /**
     * Construct new BaseDownloadForm
     */
    public function __construct() {
        $this->revision = new DownloadRevision();
        $this->publicationDay = null;
        $this->publicationMonth = null;
        $this->publicationYear = null;
        $this->formFile = null;
        $this->formImage = null;
        $this->deleteImage = false;
        $this->overwrite = false;
    }


    // ------------------------------------------------------------- Properties


    /**
     * Get Revision
     *
     * @return DownloadRevision 
     */
    public function getRevision() {
        return $this->revision;
    }


    /**
     * Set Revision
     *
     * @param DownloadRevision  revision
     */
    public function setRevision(DownloadRevision $revision) {
        $this->revision = $revision;
    }


    /**
     * Get PublicationDay
     *
     * @return mixed 
     */
    public function getPublicationDay() {
        return $this->publicationDay;
    }


    /**
     * Set PublicationDay
     *
     * @param mixed  publicationDay
     */
    public function setPublicationDay($publicationDay) {
        $this->publicationDay = $publicationDay;
    }


    /**
     * Get PublicationMonth
     *
     * @return mixed 
     */
    public function getPublicationMonth() {
        return $this->publicationMonth;
    }


    /**
     * Set PublicationMonth
     *
     * @param mixed  publicationMonth
     */
    public function setPublicationMonth($publicationMonth) {
        $this->publicationMonth = $publicationMonth;
    }


    /**
     * Get PublicationYear
     *
     * @return mixed 
     */
    public function getPublicationYear() {
        return $this->publicationYear;
    }


    /**
     * Set PublicationYear
     *
     * @param mixed  publicationYear
     */
    public function setPublicationYear($publicationYear) {
        $this->publicationYear = $publicationYear;
    }


    /**
     * Get FormFile
     *
     * @return mixed 
     */
    public function getFormFile() {
        return $this->formFile;
    }


    /**
     * Set FormFile
     *
     * @param mixed  formFile
     */
    public function setFormFile($formFile) {
        $this->formFile = $formFile;
    }


    /**
     * Get FormImage
     *
     * @return mixed 
     */
    public function getFormImage() {
        return $this->formImage;
    }


    /**
     * Set FormImage
     *
     * @param mixed  formImage
     */
    public function setFormImage($formImage) {
        $this->formImage = $formImage;
    }


    /**
     * Get DeleteImage
     *
     * @return mixed 
     */
    public function getDeleteImage() {
        return $this->deleteImage;
    }


    /**
     * Set DeleteImage
     *
     * @param mixed  deleteImage
     */
    public function setDeleteImage($deleteImage) {
        $this->deleteImage = $deleteImage;
    }


    /**
     * Get Overwrite
     *
     * @return mixed 
     */
    public function getOverwrite() {
        return $this->overwrite;
    }


    /**
     * Set Overwrite
     *
     * @param mixed  overwrite
     */
    public function setOverwrite($overwrite) {
        $this->overwrite = $overwrite;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Validate this form
     *
     * @return array $errors
     */
    public function validate() {

        $errors = new ActionMessages();

        if(is_null($this->getRevision()->getDownload()->getDescription()) || strlen($this->getRevision()->getDownload()->getDescription()) == 0)
            $errors->add("revision->download->description",
                new ActionMessage("errors.required", true, new ActionMessage("prompt.description", true)));


        if(!is_null($this->getRevision()->getDownload()->getDescription()) && strlen($this->getRevision()->getDownload()->getDescription()) > 0 && strlen($this->getRevision()->getDownload()->getDescription()) > 255)
            $errors->add("revision->download->description",
                new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.description", true),
                    new ActionMessage("255", false))));


        global $ALLOWABLE_IMAGES;
        if(!is_null($this->getFormImage()) && isset($this->formImage["size"]) && $this->formImage["size"] > 0 && !array_key_exists($this->formImage["type"], $ALLOWABLE_IMAGES))
            $errors->add("formImage",
                new ActionMessage("errors.image", true, new ActionMessage("prompt.image", true)));

        return $errors;
    }

}
?>